package com.ljy.mapper;

import com.ljy.dto.GoodsPageDTO;
import com.ljy.entity.Goods;
import com.ljy.vo.GoodsVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GoodsMapper {
    //TODO category没有添加
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into goods(name, tag, image, express, scope, pickup," +
            " description, service, video, create_time, update_time,  pay_method, invoice)" +
            "values (#{name},#{tag},#{image},#{express},#{scope},#{pickup},#{description},#{service},#{video}," +
            "#{createTime},#{updateTime},#{payMethod},#{invoice})")
    void insertGoods(Goods goods);

    List<GoodsVO> selectPage(GoodsPageDTO dto);

    @Select("select id, category_id, category_name, name, tag, image, " +
            "express, scope, pickup, description, service, video, create_time, " +
            "update_time, status, pay_method, invoice  from goods where id=#{id}" )
    Goods selectById(Integer id);

    @Update("update goods set name=#{name},tag=#{tag},image=#{image},express=#{express}," +
            "scope=#{scope},pickup=#{pickup},description=#{description},service=#{service},video=#{video}," +
            "update_time=#{updateTime},pay_method=#{payMethod},invoice=#{invoice} " +
            "where id=#{id}")
    void updateGoods(Goods goods);


    void batchDelete(List<Integer> ids);

    @Update("update goods set status=#{status} where id=#{id}")
    void changeStatus(Short status, Integer id);
}
